<template>
  <div class="main">
    <!-- 有资讯 -->
    <div class="hotList" v-if="newsList.length>0">
      <ul>
        <li
          v-for="(item,index) of newsList"
          :key="index"
          @click="()=>{goNewsDetail(item.id, 'news')}"
        >
          <div class="imgShow">
            <img :src="item.pic+'?x-oss-process=image/resize,w_270,h_270'" class="newsPic" />
          </div>
          <div class="newsInfor">
            <p>{{item.name}}</p>
            <span>发布日期：{{item.releaseTime}}</span>
          </div>
        </li>
      </ul>
    </div>
    <!-- 无内容 -->
    <div class="empty" v-else>
      <notDatas item="暂无资讯" />
    </div>
    <div>
      <div class="activeMore" v-if="!loadMore && newsList.length>0">—— 已经到底啦 ——</div>
    </div>
  </div>
</template>

<script>
import { indexInfo } from '@/api/api';
import notDatas from '@/components/notDatas';
export default {
  props: {},
  data () {
    return {
      // 资讯列表
      newsList: [],
      // 列表分页
      pages: {
        pageIndex: 1,
        pageSize: 10
      },
      loadMore: true
    };
  },
  computed: {},
  created () {},
  onShow () {},
  mounted () {
    this.pages.pageIndex = 1;
    this.loadMore = true;
    this.newsList = [];
    this.getIndexInfo(this.$mp.query.modul);
    var title = this.$mp.query.modul;
    wx.setNavigationBarTitle({
      title:
        title === 'ABOUT'
          ? '关于清和'
          : title === 'INFORMATION'
            ? '清和资讯'
            : title === 'VIEWPOINT'
              ? '清和观点'
              : title === 'SCHOOL'
                ? '清和学院'
                : title === 'COURTESY'
                  ? '财富礼遇'
                  : title === 'EXCLUSIVE'
                    ? '独家研报'
                    : '资讯列表'
    });
  },
  watch: {},
  // 下拉刷新
  onPullDownRefresh () {
    this.newsList = [];
    this.pages.pageIndex = 1;
    this.loadMore = true;
    this.getIndexInfo(this.$mp.query.modul);
    // 停止下拉刷新
    wx.stopPullDownRefresh();
  },

  // 上拉加载更多
  onReachBottom () {
    this.getIndexInfo(this.$mp.query.modul);
  },
  methods: {
    // 获取资讯列表信息
    async getIndexInfo (modul) {
      wx.showLoading({
        title: '加载中',
        mask: true
      });
      console.log(modul, this.loadMore);
      this.pages.modul = modul;
      if (this.loadMore) {
        await indexInfo(this.pages).then(res => {
          res.list.map(item => {
            item.releaseTime = item.releaseTime.substring(0, 10);
          });
          var data = res.list;
          this.newsList = this.newsList.concat(data);
          ++this.pages.pageIndex;
          if (res.pages < this.pages.pageIndex) {
            this.loadMore = false;
          }
        });
      }
      wx.hideLoading();
    },
    // 跳到资讯详情页
    goNewsDetail (id, type) {
      wx.navigateTo({
        url: `/pages/index/children/newsDetail/main?classifyId=${id}&type=${type}`
      });
    }
  },
  components: { notDatas }
};
</script>

<style scoped lang="less">
.main {
  .hotList {
    padding: 0 15px;
    background-color: #fff;
    // border-bottom: 1px solid #e6e6e6ff;
    ul {
      padding-top: 16px;
      display: flex;
      flex-direction: column;
      li {
        background-color: #fff;
        margin-bottom: 15px;
        display: flex;
        .imgShow {
          width: 90px;
          height: 90px;
          position: relative;
          margin-right: 15px;
          .newsPic {
            width: 100%;
            height: 100%;
          }
          .activeStatus {
            width: 51px;
            height: 20px;
            text-align: center;
            position: absolute;
            top: 0;
            left: 0;
            img {
              width: 100%;
              height: 100%;
              position: absolute;
              top: 0;
              left: 0;
            }
            span {
              font-size: 10px;
              font-family: PingFangSC-Medium, PingFangSC;
              font-weight: 700;
              color: rgba(255, 255, 255, 1);
              line-height: 14px;
              position: absolute;
              left: 6px;
              top: 3px;
            }
          }
        }
        .newsInfor {
          width: 240px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          p {
            font-size: 15px;
            font-family: PingFangSC-Regular, PingFangSC;
            font-weight: 700;
            color: rgba(2, 6, 4, 1);
            line-height: 21px;
            -webkit-line-clamp: 2;
          }
          span {
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFangSC;
            font-weight: 400;
            color: rgba(144, 146, 146, 1);
            line-height: 17px;
          }
        }
      }
    }
  }
  .activeMore {
    height: 74px;
    font-size: 13px;
    font-family: PingFangSC-Medium, PingFangSC;
    font-weight: 700;
    color: #b8bab9;
    line-height: 74px;
    text-align: center;
    // padding-top: 5px;
  }
}
</style>
